package com.chinasoft.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;


@Controller
public class FileUpLoadController {
    @RequestMapping("/upload")
    // @RequestPart 表单项名称和形参名不一样可以使用它来指定名称
    public void fileUpLoad(@RequestPart("pic") MultipartFile file) throws IOException {

        String name = file.getName();//表单项的名称
        String filename = file.getOriginalFilename();//文件名称
        long size = file.getSize();//文件大小
        System.out.println(name+filename+size);
        //写入磁盘
        file.transferTo(new File("D:/f/"+filename));
    }
}
